# -*- coding: utf-8 -*-
# 车内件流行
# author： 郭瑞玲
# create_time: 2022-05-13

from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from jms_hi.dm.dm_truck_wabill_flow_detail_ht import jms_hi_dm__dm_truck_wabill_flow_detail_ht


# 建拆包差异明细
jms_hi_dm__dm_truck_wabill_flow_count_ht = SparkSqlOperator(
    task_id='jms_hi_dm__dm_truck_wabill_flow_count_ht',
    task_concurrency=1,
    depends_on_past=True,
    pool_slots=2,
    master='yarn',
    execution_timeout=timedelta(minutes=120),
    email=['guoruiling@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_hi_dm__dm_truck_wabill_flow_count_ht_{{ execution_date | cst_hour }}',
    sql='jms_hi/dm/dm_truck_wabill_flow_count_ht/execute.sql',
    driver_memory='3G' , 
    driver_cores=2 , 
    executor_cores=2 , 
    executor_memory='3G' , 
    num_executors=2 , 
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
        'spark.dynamicAllocation.maxExecutors'             : 2 , 
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 180,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.sql.shuffle.partitions': 120,
          'spark.default.paralleism': 200,
          'spark.hadoop.hive.exec.dynamic.partition.mode': 'true',
          'spark.network.timeout': 900,
          'spark.core.connection.ack.wait.timeout': 300,
          'spark.sql.autoBroadcastJoinThreshold': 104857600,
          'spark.yarn.executor.memoryOverhead': 8192,
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions': 200,  # 每天生成 20 个分区
              'hive.exec.max.dynamic.partitions.pernode': 200,  # 每天生成 20 个分区
              },
    yarn_queue='pro',
    retries=2,
    sla=timedelta(minutes=120)
)


jms_hi_dm__dm_truck_wabill_flow_count_ht << [
    jms_hi_dm__dm_truck_wabill_flow_detail_ht
]
